package servlets.chatting;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.moma.chatting.core.ChattingManager;
import com.moma.chatting.core.User;

public class KeepAlive extends HttpServlet {
	private ChattingManager mgr = null;
	
	@Override
	public void init(){
		mgr = ChattingManager.getInstance();
		mgr.initialize();
    }
	
	@Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
		doPost(request, response);
		
	}
	@Override
	public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
		// http://messaging.com/keepAlive?id=abc&conversationId=1;
		String userUniqueName = request.getParameter("id");
		String conversationIdText = request.getParameter("conversationId");
		int conversationId = 0;
		if (conversationIdText != null && conversationIdText != ""){
			conversationId = Integer.valueOf(conversationIdText);
		}
		mgr.keepAlive(userUniqueName, conversationId);
//		PrintWriter out = response.getWriter();
//		out.println(conversationId);
	}
}
